<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h2>书籍的总价格：{{ totalPrice }}</h2>
    </div>

    <script src="vue.js"></script>

    <script>
        const app = new Vue({
            el: "#app",
            data: {
                books: [
                    {
                        id: 11,
                        name: "Unix编程艺术",
                        price: 56,
                    },
                    {
                        id: 12,
                        name: "代码大全",
                        price: 43,
                    },
                    {
                        id: 13,
                        name: "java从入门到跑路",
                        price: 72,
                    },
                    {
                        id: 14,
                        name: "mysql从入门到删库",
                        price: 31,
                    },
                ]
            },
            computed: {
                totalPrice: function () {
                    var sum = 0;
                    this.books.forEach(element => {
                        sum += element.price;
                    });
                    return sum;
                }
            }
        });
    </script>
</body>

</html>